package com.java.simple.study.io.bio;

import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;

/**
 * @author zhoujunlin
 * @date 2023年04月17日 14:06
 * @desc
 */
@Slf4j
public class SocketClient {

    @SneakyThrows
    public static void main(String[] args) {
        Socket so = new Socket("localhost", 9090);

        // 输入
        OutputStream outputStream = so.getOutputStream();
        outputStream.write("SocketClient: bio socket client".getBytes());

        outputStream.flush();

        // 输出
        InputStream inputStream = so.getInputStream();
        byte[] bytes = new byte[1024];
        // 阻塞等待服务端数据返回
        int len = inputStream.read(bytes);
        log.info("服务端数据返回:{}", new String(bytes, 0, len));

        so.close();

    }


}
